<?php
//导入头部页面

//include_once "config.inc.php";
include_once "header.php";
//echo $uid;

$uid = empty($_SESSION['id']) ? 0 : $_SESSION['id'];

if(isset($_POST['submit'])){
	//echo '发表............';
	if($uid > 0){
		$text = "";
		foreach($_POST['text'] as $val){
			if(!empty($val)){
				$text.=$val.'||';
			}
		}
		//去掉最后两个||
		$text = substr($text, 0, strlen($text)-2);
		//echo $text;
		$stmt = $pdo->prepare("insert into kp_test(uid,utime,title,content) values(?,?,?,?);");
		//print_r($_POST);
		$stmt->execute(array($uid,time(),$_POST['title'],$text));
		echo '<script type="text/javascript">alert("发表成功!");</script>';
	}else{
		echo '<script type="text/javascript">alert("请先登陆!");</script>';
	}
}


include_once "tpl/write.tpl";
?>
